﻿using System.Windows;
using System.Windows.Controls;

namespace Budget.Silver.Core.Controls
{
    public class NavigationLink : HyperlinkButton
    {
        public static readonly DependencyProperty CurrentStateProperty =
          DependencyProperty.Register("CurrentState", typeof(object),
          typeof(NavigationLink),
          new PropertyMetadata(CurrentStatePropertyChanged));

        public object CurrentState
        {
            get { return (object)GetValue(CurrentStateProperty); }
            set { SetValue(CurrentStateProperty, value); }
        }

        private static void CurrentStatePropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            var hyp = o as NavigationLink;
            if (hyp != null)
            {
                hyp.OnCurrentStatePropertyChanged((object)e.NewValue);
                VisualStateManager.GoToState(hyp, (string)e.NewValue, true);
            }
        }

        private void OnCurrentStatePropertyChanged(object newValue)
        {
            CurrentState = newValue;
        }
    }
}